home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / windows / ocx / ipack.exe / SERVER3.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-06-24  |  8.8 KB  |  264 lines

  1. VERSION 4.00
  2. Begin VB.MDIForm MDIForm1 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H8000000C&
  5.    Caption         =   "Socket Server"
  6.    ClientHeight    =   6405
  7.    ClientLeft      =   3135
  8.    ClientTop       =   3360
  9.    ClientWidth     =   8340
  10.    Height          =   7095
  11.    Left            =   3075
  12.    LinkTopic       =   "MDIForm1"
  13.    Top             =   2730
  14.    Width           =   8460
  15.    Begin VB.PictureBox Picture1 
  16.       Align           =   1  'Align Top
  17.       Appearance      =   0  'Flat
  18.       BackColor       =   &H00C0C0C0&
  19.       BorderStyle     =   0  'None
  20.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  21.          Name            =   "MS Sans Serif"
  22.          Size            =   8.25
  23.          Charset         =   0
  24.          Weight          =   700
  25.          Underline       =   0   'False
  26.          Italic          =   0   'False
  27.          Strikethrough   =   0   'False
  28.       EndProperty
  29.       ForeColor       =   &H80000008&
  30.       Height          =   1515
  31.       Left            =   0
  32.       ScaleHeight     =   1515
  33.       ScaleWidth      =   8340
  34.       TabIndex        =   0
  35.       Top             =   0
  36.       Width           =   8340
  37.       Begin VB.Timer Timer1 
  38.          Enabled         =   0   'False
  39.          Interval        =   1000
  40.          Left            =   7650
  41.          Top             =   780
  42.       End
  43.       Begin VB.TextBox textLocalAddress 
  44.          Appearance      =   0  'Flat
  45.          Height          =   285
  46.          Left            =   1335
  47.          TabIndex        =   3
  48.          Text            =   "0.0.0.0"
  49.          Top             =   135
  50.          Width           =   1425
  51.       End
  52.       Begin VB.TextBox textLocalPort 
  53.          Appearance      =   0  'Flat
  54.          Height          =   285
  55.          Left            =   3870
  56.          TabIndex        =   2
  57.          Text            =   "1024"
  58.          Top             =   135
  59.          Width           =   555
  60.       End
  61.       Begin VB.ListBox listStatus 
  62.          Appearance      =   0  'Flat
  63.          Height          =   810
  64.          Left            =   1335
  65.          TabIndex        =   1
  66.          Top             =   465
  67.          Width           =   6120
  68.       End
  69.       Begin AsocketLib.AsyncSocket AsyncSocket1 
  70.          Left            =   7560
  71.          Top             =   240
  72.          _Version        =   327680
  73.          _ExtentX        =   847
  74.          _ExtentY        =   847
  75.          _StockProps     =   0
  76.          ReceiveBufferSize=   8192
  77.          SendBufferSize  =   8192
  78.          BroadcastEnabled=   0   'False
  79.          LingerEnabled   =   0   'False
  80.          RouteEnabled    =   -1  'True
  81.          KeepAliveEnabled=   0   'False
  82.          OutOfBandEnabled=   0   'False
  83.          ReuseAddressEnabled=   0   'False
  84.          TCPNoDelayEnabled=   0   'False
  85.          LingerMode      =   0
  86.          LingerTime      =   0
  87.          EventMask       =   63
  88.          LocalPort       =   0
  89.          RemotePort      =   0
  90.          SocketType      =   0
  91.          LocalAddress    =   ""
  92.          RemoteName      =   ""
  93.          RemoteAddress   =   ""
  94.          ReceiveTimeout  =   -1
  95.          SendTimeout     =   -1
  96.       End
  97.       Begin VB.Line Line2 
  98.          BorderColor     =   &H00FFFFFF&
  99.          X1              =   0
  100.          X2              =   8415
  101.          Y1              =   90
  102.          Y2              =   90
  103.       End
  104.       Begin VB.Line Line1 
  105.          BorderColor     =   &H00404040&
  106.          BorderWidth     =   2
  107.          X1              =   15
  108.          X2              =   7785
  109.          Y1              =   1380
  110.          Y2              =   1380
  111.       End
  112.       Begin VB.Label Label1 
  113.          Alignment       =   1  'Right Justify
  114.          Appearance      =   0  'Flat
  115.          BackColor       =   &H00C0C0C0&
  116.          Caption         =   "Local Address:"
  117.          ForeColor       =   &H80000008&
  118.          Height          =   225
  119.          Index           =   0
  120.          Left            =   165
  121.          TabIndex        =   6
  122.          Top             =   150
  123.          Width           =   1155
  124.       End
  125.       Begin VB.Label Label1 
  126.          Alignment       =   1  'Right Justify
  127.          Appearance      =   0  'Flat
  128.          BackColor       =   &H00C0C0C0&
  129.          Caption         =   "Local Port:"
  130.          ForeColor       =   &H80000008&
  131.          Height          =   210
  132.          Index           =   1
  133.          Left            =   2940
  134.          TabIndex        =   5
  135.          Top             =   150
  136.          Width           =   840
  137.       End
  138.       Begin VB.Label Label2 
  139.          Alignment       =   1  'Right Justify
  140.          Appearance      =   0  'Flat
  141.          BackColor       =   &H00C0C0C0&
  142.          Caption         =   "Status:"
  143.          ForeColor       =   &H80000008&
  144.          Height          =   285
  145.          Left            =   435
  146.          TabIndex        =   4
  147.          Top             =   435
  148.          Width           =   855
  149.       End
  150.    End
  151.    Begin VB.Menu FileMenu 
  152.       Caption         =   "&File"
  153.       Begin VB.Menu FileExit 
  154.          Caption         =   "E&xit"
  155.       End
  156.    End
  157.    Begin VB.Menu WindowMenu 
  158.       Caption         =   "&Window"
  159.       WindowList      =   -1  'True
  160.    End
  161.    Begin VB.Menu HelpMenu 
  162.       Caption         =   "&Help"
  163.       Begin VB.Menu HelpAbout 
  164.          Caption         =   "&About"
  165.       End
  166.    End
  167. Attribute VB_Name = "MDIForm1"
  168. Attribute VB_Creatable = False
  169. Attribute VB_Exposed = False
  170. Option Explicit
  171. Private Sub AsyncSocket1_OnAccept(ByVal SocketHandle As Long, ByVal ErrorCode As Integer)
  172.     Dim foo As New formSession
  173.     foo.textSocketHandle = CStr(SocketHandle)
  174.     listStatus.AddItem "OnAccept" & Str(ErrorCode)
  175.     listStatus.AddItem "Socket Address: " & foo.AsyncSocket1.SocketAddress
  176.     If Trim$(foo.AsyncSocket1.RemoteAddress) <> "" Then
  177.         foo.lblClientIP = foo.AsyncSocket1.RemoteAddress
  178.     Else
  179.         foo.lblClientIP = "Unknown IP"
  180.     End If
  181.     foo.lblClientPort = CStr(foo.AsyncSocket1.RemotePort)
  182. End Sub
  183. Private Sub AsyncSocket1_OnClose(ByVal ErrorCode As Integer)
  184.     listStatus.AddItem "Close" & Str(ErrorCode)
  185.     AsyncSocket1.Action = ASocketClose
  186.     AsyncSocket1.Action = ASocketCreate
  187.     AsyncSocket1.Action = ASocketListen
  188. End Sub
  189. Private Sub AsyncSocket1_OnConnect(ByVal ErrorCode As Integer)
  190.     listStatus.AddItem "Connect" & Str(ErrorCode)
  191.     '
  192.     ' Remove all of the following lines if you have a known
  193.     ' address.
  194.     '
  195.     AsyncSocket1.LocalPort = 1024
  196.     AsyncSocket1.LocalAddress = AsyncSocket1.SocketAddress
  197.     textLocalAddress = AsyncSocket1.LocalAddress
  198.     AsyncSocket1.Action = ASocketClose
  199.     AsyncSocket1.Action = ASocketCreate
  200.     AsyncSocket1.Action = ASocketListen
  201. End Sub
  202. Private Sub MDIForm_Load()
  203.     '
  204.     ' note:  When running as a client on a service which
  205.     ' provides you with an ip address when you connect the
  206.     ' program must go through some hoops to get the assigned
  207.     ' ip address to use with this server example.
  208.     '
  209.     ' This sample program was tested on such a server and
  210.     ' handles the problem.  For a _real_ server this is
  211.     ' somewhat unrealistic since a real server would
  212.     ' be expected to have a known address and presumably
  213.     ' you would know what that address is.
  214.     '
  215.     AsyncSocket1.LocalPort = 0
  216.     AsyncSocket1.LocalAddress = "0.0.0.0"
  217.     '
  218.     ' Winsock won't tell us what our ip address is until
  219.     ' after we connect to some remote socket.  Here I've
  220.     ' chosen to use mit.edu.
  221.     '
  222.     AsyncSocket1.RemotePort = 13
  223.     '
  224.     ' If you can't do name lookups comment out the following
  225.     ' three lines and uncomment the one following them.
  226.     '
  227.     ' Also, if you have a known server address then remove
  228.     ' the following three lines, uncomment the fourth, and
  229.     ' supply the appropriate address there.  Be sure to remove
  230.     ' the indicated lines in OnConnect as well in this case.
  231.     '
  232.     AsyncSocket1.RemoteNameAddrXlate = True
  233.     AsyncSocket1.RemoteName = "mit.edu"
  234.     AsyncSocket1.RemoteNameAddrXlate = False
  235. '    AsyncSocket1.RemoteAddress = "18.72.2.1"
  236.     AsyncSocket1.Action = ASocketCreate
  237.     On Error Resume Next
  238.     '
  239.     ' Remove the following 5 lines if you have a known address
  240.     '
  241.     AsyncSocket1.Action = ASocketConnect
  242.     If (Err <> 0 And Err <> 10035) Then
  243.         MsgBox Error
  244.     End If
  245.     On Error GoTo 0
  246.     '
  247.     ' Uncomment the following two lines if you have a known
  248.     ' address.
  249.     '
  250.     'AsyncSocket1.Action = ASocketCreate
  251.     'AsyncSocket1.Action = ASocketListen
  252. End Sub
  253. Private Sub MDIForm_Resize()
  254.     line1.Y1 = picture1.Height - Screen.TwipsPerPixelY
  255.     line1.Y2 = line1.Y1
  256.     line2.Y1 = 0
  257.     line2.Y2 = 0
  258.     line1.X1 = 0
  259.     line1.X2 = picture1.Width
  260.     line2.X1 = 0
  261.     line2.X2 = picture1.Width
  262.     listStatus.Width = Me.ScaleWidth - (listStatus.Left + 5 * Screen.TwipsPerPixelX)
  263. End Sub
  264.